package com.leyou.item.service;

import com.leyou.common.advice.exception.LyException;
import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import enums.ExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class SpecificationService {

    @Autowired
    private SpecGroupMapper specGroupMapper;
    @Autowired
    private SpecParamMapper specParamMapper;

    public List<SpecGroup> queryGroupByCid(Long cid) {
        SpecGroup group = new SpecGroup();
        group.setCid(cid);
        List<SpecGroup> specGroups = specGroupMapper.select(group);
        if (CollectionUtils.isEmpty(specGroups)){
            //没有查到：
            throw new LyException(ExceptionEnum.BRAND_NOT_FOUND);
        }
        return specGroups;
    }

//    public List<SpecParam> queryGroupByGid(Long gid) {
//        SpecParam param = new SpecParam();
//        param.setGroupId(gid);
//        List<SpecParam> list = specParamMapper.select(param);
//        if (CollectionUtils.isEmpty(list)){
//            throw new LyException(ExceptionEnum.SPEC_PARAM_NOT_FOUND);
//        }
//        return list;
//    }

    public List<SpecParam> queryParamList(Long gid, Long cid, Boolean searching) {

        SpecParam param = new SpecParam();
        param.setGroupId(gid);
        param.setCid(cid);
        param.setSearching(searching);
        List<SpecParam> lists = specParamMapper.select(param);
        if (CollectionUtils.isEmpty(lists)){
            throw new LyException(ExceptionEnum.SPEC_PARAM_NOT_FOUND);
        }
        return lists;
    }
}
